home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / gameplan.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  7KB  |  347 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9.  
  10. #define VERBOSE_VIDEO
  11. #define SHOW_CHARS
  12.  
  13. #include "driver.h"
  14. #include "vidhrdw/generic.h"
  15.  
  16. static int gameplan_this_is_kaos;
  17. static int gameplan_this_is_megatack;
  18. static int clear_to_colour = 0;
  19. static int fix_clear_to_colour = -1;
  20. static char *colour_names[] = {"WHITE", "CYAN", "MAGENTA", "BLUE",
  21.                                "YELLOW", "GREEN", "RED", ".BLACK"};
  22.  
  23.  
  24.  
  25. void gameplan_clear_screen(void);
  26.  
  27.  
  28. /***************************************************************************
  29.  
  30.   Start the video hardware emulation.
  31.  
  32. ***************************************************************************/
  33.  
  34.  
  35. int gameplan_vh_start(void)
  36. {
  37.     if (strcmp(Machine->gamedrv->name, "kaos") == 0)
  38.         gameplan_this_is_kaos = 1;
  39.     else
  40.         gameplan_this_is_kaos = 0;
  41.  
  42.     if (strcmp(Machine->gamedrv->name, "megatack") == 0)
  43.         gameplan_this_is_megatack = 1;
  44.     else
  45.         gameplan_this_is_megatack = 0;
  46.  
  47.     return generic_bitmapped_vh_start();
  48. }
  49.  
  50.  
  51. static int port_b;
  52. static int new_request = 0;
  53. static int finished_sound = 0;
  54. static int cb2 = -1;
  55.  
  56. READ_HANDLER( gameplan_sound_r )
  57. {
  58. #ifdef VERBOSE
  59.     logerror("GAME:  read reg%X at PC %04x\n", offset, cpu_get_pc());
  60. #endif
  61.  
  62.     if (offset == 0)
  63.     {
  64. #ifdef VERBOSE
  65.         if (finished_sound)  logerror("[GAME: checking sound request ack: OK (%d)]\n", finished_sound);
  66.         else  logerror("[GAME: checking sound request ack: BAD (%d)]\n", finished_sound);
  67. #endif
  68.  
  69.         return finished_sound;
  70.     }
  71.     else
  72.         return 0;
  73. }
  74.  
  75. WRITE_HANDLER( gameplan_sound_w )
  76. {
  77. #ifdef VERBOSE
  78.     logerror("GAME: write reg%X with %02x at PC %04x\n", offset, data, cpu_get_pc());
  79. #endif
  80.  
  81.     if (offset == 1)
  82.     {
  83. #ifdef VERBOSE
  84.         logerror("[GAME: request sound number %d]\n", data);
  85. #endif
  86.  
  87.         if (cb2 == 0)
  88.         {
  89. //    enabling this causes a hang in Challenger when entering high score name
  90. //            cpu_set_reset_line(1,PULSE_LINE);
  91.             return;
  92.         }
  93.  
  94.         port_b = data;
  95.         finished_sound = 0;
  96.         new_request = 1;
  97.  
  98.         /* shortly after requesting a sound, the game board checks
  99.            whether the sound board has ackknowledged receipt of the
  100.            command - yield now to allow it to send the ACK */
  101. //        cpu_yield();    enabling this causes a hang in Challenger when entering high score name
  102.     }
  103.     else if (offset == 0x0c)    /* PCR */
  104.     {
  105.         if (data & 0x80)
  106.         {
  107.             if ((data & 0x60) == 0x60)
  108.                 cb2 = 1;
  109.             else if ((data & 0x60) == 0x40)
  110.                 cb2 = 0;
  111.             else cb2 = -1;
  112.         }
  113.     }
  114. }
  115.  
  116. READ_HANDLER( gameplan_via5_r )
  117. {
  118. #ifdef VERBOSE
  119.     logerror("SOUND:  read reg%X at PC %04x\n", offset, cpu_get_pc());
  120. #endif
  121.  
  122.     if (offset == 0)
  123.     {
  124.         new_request = 0;
  125. #ifdef VERBOSE
  126.         logerror("[SOUND: received sound request %d]\n", port_b);
  127. #endif
  128.         return port_b;
  129.     }
  130.  
  131.     if (offset == 5)
  132.     {
  133.         if (new_request == 1)
  134.         {
  135. #ifdef VERBOSE
  136.             logerror("[SOUND: checking for new request - found]\n");
  137. #endif
  138.             return 0x40;
  139.         }
  140.         else
  141.         {
  142. #ifdef VERBOSE
  143.             logerror("[SOUND: checking for new request - none]\n");
  144. #endif
  145.             return 0;
  146.         }
  147.     }
  148.  
  149.     return 1;
  150. }
  151.  
  152. WRITE_HANDLER( gameplan_via5_w )
  153. {
  154. #ifdef VERBOSE
  155.     logerror("SOUND: write reg%X with %02x at PC %04x\n", offset, data, cpu_get_pc());
  156. #endif
  157.  
  158.     if (offset == 2)
  159.     {
  160. #ifdef VERBOSE
  161.         logerror("[SOUND: ack received request %d]\n", data);
  162. #endif
  163.         finished_sound = data;
  164.     }
  165. }
  166.  
  167. READ_HANDLER( gameplan_video_r )
  168. {
  169.     static int x;
  170.     x++;
  171. #if 0
  172.     logerror("%04x: reading %d from 200d\n", cpu_get_pc(), x);
  173. #endif
  174.     return x;
  175. }
  176.  
  177. WRITE_HANDLER( gameplan_video_w )
  178. {
  179.     static int r0 = -1;
  180.     static unsigned char xpos, ypos, colour = 7;
  181.  
  182. #ifdef VERBOSE
  183.     logerror("VIA 1: PC %04x: %x -> reg%X\n", cpu_get_pc(), data, offset);
  184. #endif
  185.  
  186.     if (offset == 0)            /* write to 2000 */
  187.     {
  188.         r0 = data;
  189. #ifdef VERBOSE
  190.         logerror("  mode = %d\n", data);
  191. #endif
  192.     }
  193.     else if (offset == 1)        /* write to 2001 */
  194.     {
  195.         if (r0 == 0)
  196.         {
  197.             if (gameplan_this_is_kaos)
  198.                 colour = ~data & 0x07;
  199.             else if (data & 0x0f)
  200.             {
  201. #ifdef VERBOSE
  202.                 logerror("  !movement command %02x unknown\n", data);
  203. #endif
  204.             }
  205.  
  206. #ifdef VERBOSE_VIDEO
  207. #ifdef SHOW_CHARS
  208.             logerror("%c", colour_names[colour][0]);
  209. #else
  210.             logerror("  line command %02x at (%d, %d) col %d (%s)\n", data, xpos, ypos, colour, colour_names[colour]);
  211. #endif
  212. #endif
  213.  
  214.             if (data & 0x20)
  215.             {
  216.                 if (data & 0x80)
  217.                     ypos--;
  218.                 else
  219.                     ypos++;
  220.             }
  221.             if (data & 0x10)
  222.             {
  223.                 if (data & 0x40)
  224.                     xpos--;
  225.                 else
  226.                     xpos++;
  227.             }
  228.  
  229.             plot_pixel2(Machine->scrbitmap, tmpbitmap, xpos, ypos, Machine->pens[colour]);
  230.         }
  231.         else if (r0 == 1)
  232.         {
  233.             xpos = data;
  234. #ifdef VERBOSE_VIDEO
  235. #ifdef SHOW_CHARS
  236.             logerror("\n");
  237. #else
  238.             logerror("  X = %d\n", xpos);
  239. #endif
  240. #endif
  241.         }
  242.         else if (r0 == 2)
  243.         {
  244.             ypos = data;
  245. #ifdef VERBOSE_VIDEO
  246. #ifndef SHOW_CHARS
  247.             logerror("  Y = %d\n", ypos);
  248. #endif
  249. #endif
  250.         }
  251.         else if (r0 == 3)
  252.         {
  253.             if (offset == 1 && data == 0)
  254.             {
  255. #ifdef VERBOSE_VIDEO
  256.                 logerror("  clear screen\n");
  257. #endif
  258.                 gameplan_clear_screen();
  259.             }
  260. #ifdef VERBOSE
  261.             else logerror("  !not clear screen: offset = %d, data = %d\n", offset, data);
  262. #endif
  263.         }
  264. #ifdef VERBOSE
  265.         else
  266.         {
  267.             logerror("  !offset = %d, data = %02x\n", offset, data);
  268.         }
  269. #endif
  270.     }
  271.     else if (offset == 2)
  272.     {
  273.         if (data == 7)
  274.         {
  275.             /* This whole 'fix_clear_to_colour' and special casing for
  276.              * megatack thing is ugly, and doesn't even work properly.
  277.              */
  278.  
  279.             if (!gameplan_this_is_megatack || fix_clear_to_colour == -1)
  280.                 clear_to_colour = colour;
  281. #ifdef VERBOSE_VIDEO
  282.             if (fix_clear_to_colour == -1)
  283.                 logerror("  clear screen colour = %d (%s)\n", colour, colour_names[colour]);
  284.             else
  285.                 logerror("  clear req colour %d hidden by fixed colour %d\n", colour, fix_clear_to_colour);
  286. #endif
  287.         }
  288. #ifdef VERBOSE
  289.         else
  290.             logerror("  !offset = %d, data = %02x\n", offset, data);
  291. #endif
  292.     }
  293.     else if (offset == 3)
  294.     {
  295.         if (r0 == 0)
  296.         {
  297. #ifdef VERBOSE
  298.             if ((data & 0xf8) != 0xf8)  logerror("  !unknown data (%02x) written for pixel (%3d, %3d)\n", data, xpos, ypos);
  299. #endif
  300.  
  301.             colour = data & 7;
  302. #ifdef VERBOSE_VIDEO
  303. #ifndef SHOW_CHARS
  304.             logerror("  colour %d, move to (%d, %d)\n", colour, xpos, ypos);
  305. #endif
  306. #endif
  307.         }
  308.         else if ((data & 0xf8) == 0xf8 && data != 0xff)
  309.         {
  310.             clear_to_colour = fix_clear_to_colour = data & 0x07;
  311. #ifdef VERBOSE
  312.             logerror("  unusual colour request %d\n", data & 7);
  313. #endif
  314.         }
  315. #ifdef VERBOSE
  316.         else
  317.             logerror("  !offset = %d, data = %02x\n", offset, data);
  318. #endif
  319.     }
  320. #ifdef VERBOSE
  321.     else
  322.         logerror("  !offset = %d, data = %02x\n", offset, data);
  323. #endif
  324. }
  325.  
  326.  
  327. /***************************************************************************
  328.  
  329.   Draw the game screen in the given osd_bitmap.
  330.   Do NOT call osd_update_display() from this function, it will be called by
  331.   the main emulation engine.
  332.  
  333. ***************************************************************************/
  334.  
  335.  
  336. void gameplan_clear_screen(void)
  337. {
  338. #ifdef VERBOSE_VIDEO
  339.     logerror("  clearing the screen to colour %d (%s)\n", clear_to_colour, colour_names[clear_to_colour]);
  340. #endif
  341.  
  342.     fillbitmap(tmpbitmap, Machine->pens[clear_to_colour], 0);
  343.     fillbitmap(Machine->scrbitmap, Machine->pens[clear_to_colour], 0);
  344.  
  345.     fix_clear_to_colour = -1;
  346. }
  347.